package cn.didi.feidi.androidorder.util;

import java.util.regex.Pattern;

/**
 * Created by king on 2017/8/30.
 */

public class DataCheckUtil {
    public static final String PHONE_NUMBER_REGEX="[1][358]\\d{9}";//手机号码正则表达式
    public static final String FEIDI_ACCOUNT_REGEX="^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}$";//飞滴号正则表达式
    public static final String ID_CARD_NO_REGEX="(\\\\d{14}[0-9a-zA-Z])|(\\\\d{17}[0-9a-zA-Z])";//身份证正则表达式
    public static final Pattern PHONE_NUMBER_PATTERN=Pattern.compile(PHONE_NUMBER_REGEX);
    public static final Pattern FEIDI_ACCOUNT_PATTERN=Pattern.compile(FEIDI_ACCOUNT_REGEX);
    public static final Pattern ID_CARD_NO_PATTERN=Pattern.compile(ID_CARD_NO_REGEX);
  /*  *//**
     * 是否为正确的密码
     * @param password
     * @return
     *//*
    public static boolean isRightPWD(String password){
        if(isEmpty(password))
            return false;
        return PWD_PATTERN.matcher(password).matches();
    }*/

    /**
     * 是否为正确的手机号码
     * @param phoneNumber
     * @return
     */
    public static boolean isRightPhoneNumber(String phoneNumber){
        if(isEmpty(phoneNumber))
            return false;
        return PHONE_NUMBER_PATTERN.matcher(phoneNumber).matches();
    }

    /**
     * 是否为空字符串
     * @param data
     * @return
     */
    public static boolean isEmpty(String data){
        return data==null||data.length()==0;
    }
/*
    *//**
     * 验证手机和密码格式是否正确
     * @throws Exception
     *//*
    public  static void  checkPhoneNumberAndPwd(String phoneNumber,String password) throws Exception {
        if(!DataCheckUtil.isRightPhoneNumber(phoneNumber))
            throw new MyException(CommonProtocol.WRONG_PHONE_NUMBER, CommonMessage.WRONG_PHONE_NUMBER);
        else if (!DataCheckUtil.isRightPWD(password))
            throw new MyException(CommonProtocol.WRONG_PASSWORD,CommonMessage.WRONG_PASSWORD);

    }*/

    /**
     * 验证飞滴号是否正确
     * @param account
     * @return
     */
    public  static boolean isRightFeidiAccount(String account){
        if (isEmpty(account))
            return   false;
        if (!FEIDI_ACCOUNT_PATTERN.matcher(account).matches())
            return false;
        return true;
    }
    /**
     * 验证一个Integer值是否在范围内
     */
    public  static boolean isBetweenScope(Integer number,Integer scope1,Integer scope2){
        if(number==null||scope1==null||scope2==null){
            return false;
        }
        int min = Math.min(scope1,scope2);
        int max = Math.max(scope1,scope2);
        return (number>=min)&&(number<=max);
    }
    /**
     * 验证身份证是否正确
     */
    public static boolean isRightIdCardNo(String idCardNo){
        if(isEmpty(idCardNo))
            return false;
        return ID_CARD_NO_PATTERN.matcher(idCardNo).matches();
    }
}
